Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call 'toArray()' with an empty array instead of a pre-sized array #5277

Merged
merged 2 commits into from
Nov 16, 2022
Merged

Call 'toArray()' with an empty array instead of a pre-sized array #5277

merged 2 commits into from
Nov 16, 2022

Conversation

adnapibar
Copy link
Contributor

Description

Calls to Collection.toArray() is not consistent and in many places and use a pre-sized array parameter. This change refactors the calls to consistently use toArray(new T[0]). The empty array usage is considered faster, safer and cleaner than the sized based array approach.

Ref: https://shipilev.net/blog/2016/arrays-wisdom-ancients/

Issues Resolved

N/A

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Rabi Panda [email protected]

@adnapibar adnapibar requested review from a team and reta as code owners November 16, 2022 02:41
Calls to `Collection.toArray()` is not consistent and in many places and use a pre-sized array parameter. This change makes a consistent use of the `toArray(new T[0])`. The empty array usage is considered faster, safer and cleaner than the sized based array approach.

Signed-off-by: Rabi Panda <[email protected]>
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

  • RESULT: null ❌
  • FAILURES:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

  • RESULT: null ❌
  • FAILURES:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

CHANGELOG.md Outdated Show resolved Hide resolved
Signed-off-by: Rabi Panda <[email protected]>
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@reta
Copy link
Collaborator

reta commented Nov 16, 2022

Just a comment on the subject, seems like similar changes are making its way into JDK (https://bugs.openjdk.org/browse/JDK-8258804 fe)

@reta
Copy link
Collaborator

reta commented Nov 16, 2022

Just for the record, it seems like new T[0] is equivalent to T[]::new, I have no particular preference towards one or another.

@adnapibar
Copy link
Contributor Author

adnapibar commented Nov 16, 2022

Just a comment on the subject, seems like similar changes are making its way into JDK (https://bugs.openjdk.org/browse/JDK-8258804 fe)

No, I think the issue is just to update it internally in JDK. This is the commit openjdk/jdk@39e03a0b

@adnapibar
Copy link
Contributor Author

Just a comment on the subject, seems like similar changes are making its way into JDK (https://bugs.openjdk.org/browse/JDK-8258804 fe)

No, I think the issue is just to update it internally in JDK. This is the commit openjdk/jdk@39e03a0b

I think I misunderstood your comment earlier. Yes, there were a few places they have updated it.

@adnapibar adnapibar merged commit 9fc3f40 into opensearch-project:main Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants